package com.comdo.newup_loan.util.update;


import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.comdo.newup_loan.R;
import com.comdo.newup_loan.util.DialogUtil;


public class UpdateDialog extends Dialog {
	private TextView quit_message, quit_cancel, quit_ok, codename;
	private String desc, code_name;
	private ICallBack icall;
	private Activity activity;
	private Dialog dialog;

	public interface ICallBack {
		void callwitch();
	}

	public UpdateDialog(Context context, ICallBack icall, String desc,
			String code_name) {
		super(context, R.style.mydialog1);
		this.icall = icall;
		this.desc = desc;
		this.code_name = code_name;
		activity = (Activity) context;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_update);
		quit_cancel = (TextView) findViewById(R.id.quit_cancel);
		quit_cancel.setText("以后再说");
		quit_message = (TextView) findViewById(R.id.quit_message);
		quit_message.setText(desc);
		quit_ok = (TextView) findViewById(R.id.quit_ok);
		quit_ok.setText("立即下载");
		codename = (TextView) findViewById(R.id.code_name);
		codename.setText("新版本 " + code_name);
		
		quit_ok.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (NetworkUtil.getConnectedType(activity)) {
				case 0:
					dialog = DialogUtil.getOperateConfirmDialg(activity,
							"当前非WIFI状态下,是否下载?", new View.OnClickListener() {

								@Override
								public void onClick(View v) {
									icall.callwitch();
									if (dialog != null) {
										dialog.dismiss();
									}
								}
							});
					dismiss();
					break;
				case 1:
					icall.callwitch();
					dismiss();
					break;
				case -1:
					Toast.makeText(activity, "没有网络!",Toast.LENGTH_SHORT).show();
					dismiss();
					break;
				default:
					break;
				}
			}
		});
		quit_cancel.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dismiss();

			}
		});
	}

}
